/*
** file_generator_utils.c for ftrace in /home/windel/Documents/Tek2/System_Unix/ftrace/pullup-project/sources
** 
** Made by nicolas simon
** Login   <simon_n@epitech.net>
** 
** Started on  Sun Jul  1 16:55:21 2012 nicolas simon
** Last update Sun Jul  1 16:58:39 2012 nicolas simon
*/

#include		"../includes/ftrace.h"

int			get_token(t_token *tok, char *to_find)
{
  t_token		*tmp;

  tmp = tok;
  while (tmp)
    {
      if (strcmp(tok->name, to_find) == 0)
	return (tok->number);
      tmp = tmp->next;
    }
  write(2, "Error : couldn't find token in database.\n", 41);
  exit (-1);
}

char			*make_string(int parent, int son, int *length)
{
  *length = sprintf(ret, "%d -> %d;\n", parent, son);
  return (ret);
}

void			write_database(t_token *tok, int fd)
{
  t_token		*tmp;
  int			length;
  char			*to_write;

  tmp = tok;
  while (tmp)
    {
      length = sprintf(to_write, "%d [label=\"%s\"];\n",
		       tok->number, tok->name);
      write(fd, to_write, length);
      tmp = tmp->next;
    }
}
